﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace zp.mk.KontaktASP
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            for (int i = 2013; i >= 1900; i--)
            {
                ListItem li = new ListItem();
                li.Text = i.ToString();
                li.Value = i.ToString();
                birthyear.Items.Add(li);
            }
        }

        protected void sned_Click(object sender, EventArgs e)
        {
            String sName = name.Text;
            String sFirstname = firstname.Text;
            int iBirthyear = int.Parse(birthyear.SelectedValue);
            String sAnmerkungen = gefasel.Text;
            
            List<string> os = new List<string>();
            if (win.Checked) os.Add("windows");
            if (lin.Checked) os.Add("linux");
            if (osx.Checked) os.Add("osx");
            if (android.Checked) os.Add("android");
            if (winphone.Checked) os.Add("windowsphone");
            if (ios.Checked) os.Add("ios");

            string sSeperator = ";";

            string sOs = String.Empty;
            bool first = true;
            foreach (string one in os)
            {
                if (!first)
                {
                    sOs += "+";
                }
                sOs += one;
                first = false;
            }

            String gender = String.Empty;
            if (m.Checked)
            {
                gender = "male";
            }
            else
            {
                gender = "female";
            }

            String sLine = sName + sSeperator + sFirstname+sSeperator+gender + sSeperator + iBirthyear.ToString() + sSeperator + sOs + sSeperator + sAnmerkungen;

            StreamWriter sr = new StreamWriter(Server.MapPath("/")+"/data.csv", true);
            sr.WriteLine(sLine);
            sr.Close();
        }
    }
}